package com.htrq.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.htrq.entity.HDept;
import com.htrq.service.HDeptService;

@Controller
public class HDeptController {
	@Resource
	private HDeptService hdService;
	
	@RequestMapping("jsp/sys/getAllDept")
	@ResponseBody
	public String getAllDept(HttpServletResponse response) throws IOException{
		List<HDept> list=hdService.getAllDept();
		String str=JSON.toJSONString(list);
		response.setContentType("text/html;charset=utf8");
		PrintWriter out= response.getWriter();
		out.print(str);
		return null;
	}
	@RequestMapping("jsp/sys/savedept")
	@ResponseBody
	public String savedept(HttpServletResponse response,HDept hdept) throws IOException{
		boolean flag= hdService.savedept(hdept);
		response.setContentType("text/html;charset=utf8");
		PrintWriter out = response.getWriter();
		if(flag){
			out.print("{'success':true,'res':{'result':'添加成功'}}");
		}else{
			out.print("{'success':true,'res':{'result':'添加失败'}}");
		}
		return null;
	}
	@RequestMapping("jsp/public/getDeptNodes")
	@ResponseBody
	public String getDeptnodes(HttpServletResponse response,HDept hdept) throws IOException{
		List<HDept> list=hdService.getDeptnodes(hdept);
		String str=JSON.toJSONString(list);
		response.setContentType("text/html;charset=utf8");
		PrintWriter out= response.getWriter();
		out.print(str);
		return null;
	}
}
